<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <input type="text" id="num1">
    <input type="text" id="num2">
    <input type="button" value="加" onclick="f1()">
    <input type="button" value="减" onclick="f2()">
    <input type="button" value="乘" onclick="f3()">
    <input type="button" value="除" onclick="f4()">
    <h3>结果：<span></span></h3>
</body>
<script>

    let n1 = document.querySelector("#num1");
    let n2 = document.querySelector("#num2");
    let result_span = document.querySelector("span");

    function f1() {
        if (isNaN(n1.value) || isNaN(n2.value)){
            result_span.innerText = "输入有误！";
            return;
        }
        //当字符串进行算法的时候，转为数字number
        result_span.innerText = n1.value*1 + n2.value*1;
    }
    function f2() {
        if (isNaN(n1.value) || isNaN(n2.value)){
            result_span.innerText = "输入有误！";
            return;
        }
        //当字符串进行算法的时候，转为数字number
        result_span.innerText = n1.value - n2.value;
    }
    function f3() {
        if (isNaN(n1.value) || isNaN(n2.value)){
            result_span.innerText = "输入有误！";
            return;
        }
        //当字符串进行算法的时候，转为数字number
        result_span.innerText = n1.value * n2.value;
    }
    function f4() {
        if (isNaN(n1.value) || isNaN(n2.value)){
            result_span.innerText = "输入有误！";
            return;
        }
        //当字符串进行算法的时候，转为数字number
        result_span.innerText = n1.value / n2.value;
    }


</script>
</html>
